<?php
namespace app\api\controller\question;

use app\api\validate\question\SignValidate;
use app\common\annotation\ApiNodeAnnotation;
use app\common\controller\ApiBase;
use app\question\model\QuestionExamSignUser;

/**
 * @ApiNodeAnnotation(
 *     title="题库Api",
 *     parent="default",
 *     is_release=0,
 *     auth=1,
 * )
 */
class Index extends ApiBase
{
    /**
     * @ApiNodeAnnotation(
     *     title="考试报名用户",
     *     parent="api/question.index",
     *     is_release=1,
     *     auth=1,
     * )
     */
    public function examsignuser()
    {
        $examUsuerList = (new QuestionExamSignUser())
            ->page($this->request->param('page',0,'intval'))
            ->limit($this->request->param("limit",15,'intval'))
            ->field('id,name,telphone')
            ->select();
        $this->success("考试报名用户",'',$examUsuerList);
    }

    /**
     * @ApiNodeAnnotation(
     *     title="用户考试报名接口",
     *     parent="api/question.index",
     *     is_release=1,
     *     auth=1,
     * )
     */
    public function sign()
    {
        if($this->request->isPost())
        {
            $input = $this->request->post();
            $signValidate = new SignValidate();
            if(!$signValidate->check($input)) $this->error($signValidate->getError());
            $signUserModel = new QuestionExamSignUser();
            $signUser = $signUserModel->where("exam_id",$input['exam_id'])
                ->where("telphone",$input['telphone'])
                ->find();
            if($signUser) $this->error("请勿重复提交信息");
            $result =$signUserModel->createDatas($input);
            if ($result)
            {
                $this->success("报名成功");
            }else{
                $this->error("报名失败");
            }
        }
    }

}